package ModelLayer;
import java.util.ArrayList;


public class Items
{
    //instance variables
    private static Items instance = null;
    private static ArrayList<Item> items;
   
    /**
     * Empty constructor for testing purposes
     */
    
    private Items()
    {
       items=new ArrayList<Item>();
    }

    /**
     * Singleton static inplementation
     */
    
    public static Items getInstance()
    {
        if(instance == null)
      {
        instance = new Items();
      }
      return instance;
    }
   
    /**
     * Accessor and Mutator methods
     */
    
    public static void addItem(Item _item)
    {
        items.add(_item);
    }
    
    public static Item getItem(String _id)
    {
        Item o = new Item();
        for(int i = 0; i<items.size(); i++)  
        {
            if (items.get(i).getId().equals(_id))
                o = items.get(i);
        }
        return o;
    }
    
    public static void listAllItems()
    {
        System.out.println("\nItems:");
        for(int i = 0; i < items.size(); i++)
        {
            System.out.println("\nId: " + items.get(i).getId() +
                                "\nName: " + items.get(i).getName());
        }
    }
    
    public static int getSize()
    {
        return items.size();
    }
}
